package com.txby.hisJob.config;

import javax.servlet.DispatcherType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import com.txby.hisJob.component.interceptor.CrossFilter;
import com.txby.hisJob.component.interceptor.IndexListener;
import com.txby.hisJob.component.interceptor.XssFilter;
@Configuration
public class ServerConfig  implements EnvironmentAware{
	@Autowired private Environment env;
	@Bean
	public FilterRegistrationBean indexFilterRegistration() {
		//添加跨域过滤器
		FilterRegistrationBean registration = new FilterRegistrationBean(new CrossFilter());
//		registration.addUrlPatterns("/");
		return registration;
	}
/*	   @Bean
	    public FilterRegistrationBean xssFilterRegistration() {
	        FilterRegistrationBean registration = new FilterRegistrationBean();
	        registration.setDispatcherTypes(DispatcherType.REQUEST);
	        registration.setFilter(new XssFilter(env));
//	        registration.setFilter(new XssFilter());
	        registration.addUrlPatterns("/*");
	        registration.setName("xssFilter");
	        registration.setOrder(Integer.MAX_VALUE);
	        return registration;
	    }*/
/*	@Bean
	public FilterRegistrationBean indexFilterRegistration2() {
		//添加安全过滤器
		FilterRegistrationBean registration = new FilterRegistrationBean(new XssAndSqlFilter());
//		registration.addUrlPatterns("/");
		return registration;
	}*/

	@Bean
	public ServletListenerRegistrationBean servletListenerRegistrationBean() {
		ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean();
		servletListenerRegistrationBean.setListener(new IndexListener());
		return servletListenerRegistrationBean;
	}

	/* (非 Javadoc) 
	* <p>Title: setEnvironment</p> 
	* <p>Description: </p> 
	* @param environment 
	* @see org.springframework.context.EnvironmentAware#setEnvironment(org.springframework.core.env.Environment) 
	*/
	@Override
	public void setEnvironment(Environment environment) {
		// TODO Auto-generated method stub
		
	}

}
